<?php

declare(strict_types=1);
/**
 * This file is part of MoChat.
 * @link     https://mo.chat
 * @document https://mochat.wiki
 * @contact  group@mo.chat
 * @license  https://github.com/mochat-cloud/mochat/blob/master/LICENSE
 */
namespace MoChat\App\Common\Action\Dashboard;

use Hyperf\DbConnection\Db;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use MoChat\App\Common\Model\District as ModelDistrict;
use MoChat\Framework\Action\AbstractAction;
use MoChat\Framework\Request\ValidateSceneTrait;

/**
 * 省市区树.
 * @Controller
 */
class District extends AbstractAction
{
    use ValidateSceneTrait;

    /**
     * @RequestMapping(path="/dashboard/common/district", methods="GET")
     */
    public function handle(): array
    {
        $res = ModelDistrict::query()->where('level','<=',3)->get(['id','name','parent_id','level'])->toArray();
        $res = my_array_to_tree($res);
        return $res;
    }


    /**
     * 验证规则.
     */
    protected function rules(): array
    {
        return [
        ];
    }

    /**
     * 获取已定义验证规则的错误消息.
     */
    protected function messages(): array
    {
        return [
        ];
    }
}
